package com.glp.work.flow.config;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @author liwenhong
 * @title 初始化线程池
 * @date 2018/11/11.
 */
@Configuration
public class ThreadPoolTaskExecutorConfig {
	
  	@Value("${threadPool.corePoolSize}")
  	private Integer corePoolSize;
  	@Value("${threadPool.keepAliveSeconds}")
  	private Integer keepAliveSeconds;
  	@Value("${threadPool.maxPoolSize}")
  	private Integer maxPoolSize;
  	@Value("${threadPool.queueCapacity}")
  	private Integer queueCapacity;

  @Bean
  @Primary
  public ThreadPoolTaskExecutor init(){
	ThreadPoolTaskExecutor tp = new ThreadPoolTaskExecutor();
	tp.setCorePoolSize(corePoolSize);
	tp.setKeepAliveSeconds(keepAliveSeconds);
	tp.setMaxPoolSize(maxPoolSize);
	tp.setQueueCapacity(queueCapacity);
	return tp;
  }
}
